#include "EquationSolver.h"
#include <limits>

double pi = acos(-1);
double eps = numeric_limits<double>::epsilon();

class Func1 : public Function{
public:
  double operator()(double x){
    return sin(x/2)-1;
  }
};

Func1 f1;

double test1(){
  Secant solver(f1, 0, pi/2, eps, eps, 100);
  double result = solver.solve();
  return result;
}

class Func2 : public Function{
public:
  double operator()(double x){
    return exp(x)-tan(x);
  }
};

Func2 f2;

double test2(){
  Secant solver(f2, 1.0, 1.4, eps, eps, 100);
  double result = solver.solve();
  return result;
}

class Func3 : public Function{
public:
  double operator()(double x){
    return pow(x,3)-12*pow(x,2)+3*x+1;
  }
};

Func3 f3;

double test3(){
  Secant solver(f3, 0, -0.5, eps, eps, 100);
  double result = solver.solve();
  return result;
}

int main(){
  cout << "The root of sin(x/2)-1 in 0~pi/2 is " << test1() << endl;
  cout << "The root of exp(x)-tan(x) in 1~1.4 is " << test2() << endl;
   cout << "The root of pow(x,3)-12*pow(x,2)+3*x+1 in -0.5~1 is " << test3() << endl;
  return 0;
}
